<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>Title</title>
    <style>
        .hide {
            pointer-events: none;
            color: gray;
        }
    </style>
    <script src="js/jquery-3.6.3.min.js.txt"></script>
</head>
<body>
<%@include file="/checkLogin.jsp"%>
<div>
    <form action="showScore.do" id="searchForm">
        <input type="hidden" name="pageNo" id="pageNo" value="1">
        <input type="hidden" name="stuno"  value="${stuno}">
        <input name="subjectname" value="${subjectname}" placeholder="课程"/>
        入学时间从<input type="date" name="start" value='<fmt:formatDate value="${start}" pattern="yyyy-MM-dd" />' />-
        <input type="date" name="end" value='<fmt:formatDate value="${end}" pattern="yyyy-MM-dd" />'/>
        <input type="submit" value="搜索">
    </form>
    <a href="addStudent.jsp">添加新成绩</a>
</div>
<table border="1" width="100%" cellpadding="0" cellspacing="0">
    <tr>
        <th>编号</th>
        <th>姓名</th>
        <th>课程</th>
        <th>成绩</th>
        <th>考试日期</th>
        <th>操作</th>
    </tr>
    <c:forEach items="${p.data}" var="e">
    <tr>
        <td>${e.id}</td>
        <td>${e.sname}
        </td>
        <td>${e.subjectname}
        </td>
        <td>${e.score}
        </td>
        <td><fmt:formatDate value="${e.examDate}" pattern="yyyy/MM/dd"/>
        </td>
        <td>待定</td>
    </tr>
    </c:forEach>
</table>
<p id="pager">
    <a href="#" data-page="1">首页</a>
    <a  href="#" <c:if test="${p.pageNo<=1}">  class='hide' </c:if> >上一页</a>
    <span><input type="number" min="1" id="goto" value="${p.pageNo}" max="${p.pageTotal}" style="width: 48px" /><input type="button" id="go" value="Go"/>/${p.pageTotal}</span>
    <a  href="#" <c:if test="${p.pageNo>=p.pageTotal}"> class='hide'</c:if>  data-page="${p.pageNo+1}">下一页</a>
    <a  href="#" data-page="${p.pageTotal}">尾页</a>
</p>

<script>
  $(function () {
      $("#go").click(function () {
          let pageNo=$(this).prev().val();
          $("form#searchForm #pageNo").val(pageNo);
          $("form#searchForm").submit();
          return false;
      });
      $("#goto").keyup(function (event) {
          if(event.keyCode==13){
              let pageNo=$(this).val();
              $("form#searchForm #pageNo").val(pageNo);
              $("form#searchForm").submit();
              return false;
          }
          return false;
      });
     $("#pager a").click(function () {
         let pageNo=$(this).attr("data-page");
         $("form#searchForm #pageNo").val(pageNo);
         $("form#searchForm").submit();
         return false;
     });
  });
</script>
</body>
</html>
